<?
 include "/webs/sks-keyservers.net/status/exclude.inc.php";
 
 $exclude = ((is_array($exclude)) ? $exclude : array()); 

 class sks_status_collection
 {
  private $servers = array();
  
  public function run(&$arr)
  {
   $numkey=0;
     
   foreach($arr->get_servers() as $server)
   {
    if($server->get_hostname()=="keys.kfwebs.net")
    {
     $numkey=(int)($server->get_numkeys());
     break;
    }
   }
   
   if($numkey=="0") echo "error, number of keys on primary server not set, all keyservers will be added to pool even with large diffs";

   foreach($arr->get_servers() as $server=>$serverobj)
   {
    if(!isset($this->servers[$server]))
    {
     $this->servers[$server] = array();
     $this->servers[$server]['added']=time();
    }
    
    if($this->servers[$server]['last_status'] != $serverobj->get_statusok())
    {
     $this->servers[$server]['last_status'] = $serverobj->get_statusok();
     $this->servers[$server]['last_status_change'] = time();
    }
    
    if($serverobj->get_statusok()!=1) $this->servers[$server]['last_status_reason'] = "Not responding";
    
    if($this->servers[$server]['last_status']==1)
    {
     
     $diff = ($numkey - (int)($serverobj->get_numkeys()));
     if($diff >= 500)
     {
      if($this->servers[$server]['last_status']==1) $this->servers[$server]['last_status_change'] = time();
      $this->servers[$server]['last_status'] = 0;
      $this->servers[$server]['last_status_reason'] = "Missing keys";
     }
     //print_r($exclude);
     if(in_array($serverobj->get_hostname(), $exclude))
     {
      if($this->servers[$server]['last_status']==1) $this->servers[$server]['last_status_change'] = time();
      $this->servers[$server]['last_status'] = 0;
      $this->servers[$server]['last_status_reason'] = "In exclude list";
     }
    }
   }
  }
  
  public function get_servers()
  {
   return $this->servers;
  }
 }
?>
